package com.fuzzyclassification;

import java.util.ArrayList;
import java.util.List;

import com.fuzzyclassification.utils.LeituraXLS;
import com.fuzzyclassification.utils.RegraFuzzy;

public class TesteFuzzy {
    
    private WangMendelImpl wangMendel;
    private LeituraXLS xls;
    
    public TesteFuzzy(WangMendelImpl wangMendel, LeituraXLS xls)
    {
        this.wangMendel = wangMendel;
        this.xls = xls;
    }
    
    public void executarTestes()
    {
        List<RegraFuzzy> fuzzy = criarRegras(xls.lerPlanilha(1, 0));
        System.out.println("FUZZY TAMANHO: "+fuzzy.size());
        
        avaliarRegras(fuzzy);
//        xls.escreverXLS(wangMendel.getFuzzy(), wangMendel.getIdade(), wangMendel.getAno(), wangMendel.getNodulo(), 
//                "Trapezoidal",fuzzy);
        int count = 0;
        for (RegraFuzzy regra : wangMendel.getFuzzy()){
        	System.out.print("IF STG IS "+regra.getSTG().getNome());
        	System.out.print(" AND SCG IS "+regra.getSCG().getNome());
        	System.out.print(" AND STR IS "+regra.getSTR().getNome());
        	System.out.print(" AND LPR IS "+regra.getLPR().getNome());
        	System.out.print(" AND PEG IS "+regra.getPEG().getNome());
        	System.out.print(" THEN CLASS IS "+regra.getRegra().getClasse());
        	System.out.println();
        	count++;
        }
        System.out.println("Regras Fuzzy: "+count);
    }
    
    private void avaliarRegras(List<RegraFuzzy> fuzzy)
    {
        for(RegraFuzzy fuz: fuzzy)
        {
            fuz.getRegra().setClassificacao(wangMendel.getClassificacao(fuz));
        }
    }
    
    
    private List<RegraFuzzy> criarRegras(List<Regra> regras)
    {
        System.out.println("FUZZY TAMANHO: "+regras.size());
        List<RegraFuzzy> fuzzy = new ArrayList();
        for(Regra reg : regras)
        {
           RegraFuzzy rf = new RegraFuzzy(reg);
           rf.setFuzzySTG(wangMendel.getSTG());
           rf.setFuzzySCG(wangMendel.getSCG());
           rf.setFuzzySTR(wangMendel.getSTR());
           rf.setFuzzyLPR(wangMendel.getLPR());
           rf.setFuzzyPEG(wangMendel.getPEG());
           
           fuzzy.add(rf);
        }
        
        return fuzzy;
    }
}

